package com.ruoyi.framework.config;

import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import com.getui.push.v2.sdk.api.UserApi;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @author ab785
 * createTime: 2021-12-2.
 * description: 个推
 */
@Configuration
@ConfigurationProperties(prefix = "push.getui")
@Setter
@ConditionalOnProperty(prefix = "push.getui",name = "enable",havingValue = "true")
public class PushGetuiConfig {

    private String appId;

    private String appKey;

    private String appSecret;

    private String masterSecret;

    /**
     * ApiHelper
     *
     * @return
     */
    @Bean
    public ApiHelper apiHelper() {
        // 设置httpClient最大连接数，当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
        System.setProperty("http.maxConnections", "200");
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        //填写应用配置
        apiConfiguration.setAppId(appId);
        apiConfiguration.setAppKey(appKey);
        apiConfiguration.setMasterSecret(masterSecret);
        // 接口调用前缀，请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
        apiConfiguration.setDomain("https://restapi.getui.com/v2/");
        // 实例化ApiHelper对象，用于创建接口对象
        return ApiHelper.build(apiConfiguration);
    }

    /**
     * 推送API
     */
    @Bean
    public PushApi pushApi(ApiHelper apiHelper) {
        return apiHelper.creatApi(PushApi.class);
    }

    /**
     * 用户API
     */
    @Bean
    public UserApi userApi(ApiHelper apiHelper) {
        return apiHelper.creatApi(UserApi.class);
    }
}
